package cn.iocoder.yudao.module.alipay.service.infoslideshow;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.alipay.controller.admin.infoslideshow.vo.*;
import cn.iocoder.yudao.module.alipay.dal.dataobject.infoslideshow.InfoSlideshowDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.alipay.convert.infoslideshow.InfoSlideshowConvert;
import cn.iocoder.yudao.module.alipay.dal.mysql.infoslideshow.InfoSlideshowMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.alipay.enums.ErrorCodeConstants.*;

/**
 * 轮播图 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class InfoSlideshowServiceImpl implements InfoSlideshowService {

    @Resource
    private InfoSlideshowMapper infoSlideshowMapper;

    @Override
    public Long createInfoSlideshow(InfoSlideshowCreateReqVO createReqVO) {
        // 插入
        InfoSlideshowDO infoSlideshow = InfoSlideshowConvert.INSTANCE.convert(createReqVO);
        infoSlideshowMapper.insert(infoSlideshow);
        // 返回
        return infoSlideshow.getId();
    }

    @Override
    public void updateInfoSlideshow(InfoSlideshowUpdateReqVO updateReqVO) {
        // 校验存在
        validateInfoSlideshowExists(updateReqVO.getId());
        // 更新
        InfoSlideshowDO updateObj = InfoSlideshowConvert.INSTANCE.convert(updateReqVO);
        infoSlideshowMapper.updateById(updateObj);
    }

    @Override
    public void deleteInfoSlideshow(Long id) {
        // 校验存在
        validateInfoSlideshowExists(id);
        // 删除
        infoSlideshowMapper.deleteById(id);
    }

    private void validateInfoSlideshowExists(Long id) {
        if (infoSlideshowMapper.selectById(id) == null) {
            throw exception(INFO_SLIDESHOW_NOT_EXISTS);
        }
    }

    @Override
    public InfoSlideshowDO getInfoSlideshow(Long id) {
        return infoSlideshowMapper.selectById(id);
    }

    @Override
    public List<InfoSlideshowDO> getInfoSlideshowList(Collection<Long> ids) {
        return infoSlideshowMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<InfoSlideshowDO> getInfoSlideshowPage(InfoSlideshowPageReqVO pageReqVO) {
        return infoSlideshowMapper.selectPage(pageReqVO);
    }

    @Override
    public List<InfoSlideshowDO> getInfoSlideshowList(InfoSlideshowExportReqVO exportReqVO) {
        return infoSlideshowMapper.selectList(exportReqVO);
    }

    @Override
    public List<InfoSlideshowDO> getListByTypeId(String typeId) {
        return infoSlideshowMapper.selectListByTypeId(typeId);
    }

}
